package model.semantics;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import model.State;

public class AggregatorNode<T> extends Node<T> {
    private List<Node<T>> myChildren;

    public AggregatorNode(List<Node<T>> values) {
        myChildren = values;
    }

    public List<Node<T>> getList() {
        return Collections.unmodifiableList(myChildren);
    }

    @Override
    public T evaluate(State<T> state) {
        T output = null;
        for (Node<T> child : myChildren) {
            output = child.evaluate(state);
        }

        return output;
    }

    public List<T> evaluateList(State<T> state) {
        List<T> rtn = new LinkedList<T>();
        for (Node<T> child : myChildren) {
            rtn.add(child.evaluate(state));
        }
        return rtn;
    }

    @Override
    public String toString() {
        return String.format("(agg %s)", myChildren.toString());
    }
}
